<?php

namespace App\Console\Commands;

use App\Jobs\Viewer;
use App\Models\History;
use App\Models\Position;
use App\Services\CrawlerService\CrawlerService;
use App\Services\CrawlerService\driver\Xinxin21ccnnDriver;
use App\Services\LbsService\LbsService;
use App\Services\TagService\TagService;
use Illuminate\Console\Command;

class FixHistory extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'fix_history';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $history = \DB::table('histories')->selectRaw('member_id,position_id,count(id) as times,max(created_at) as updated_at')
            ->groupBy('member_id')->groupBy('position_id')->get()->map(function ($value) {
                return (array)$value;
            })->toArray();
        \DB::table('histories')->delete();
        \DB::table('histories')->insert($history);
    }
}
